package com.orm.handler;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 *  数据库： BigInteger 对应   Java 类型: BigDecimal
 */
public class BigIntegerTypeHandler extends BaseTypeHandler<BigInteger> {
	
	@Override
	public void setNotNullParameter(PreparedStatement ps, int i, BigInteger parameter, JDBCType jdbcType) throws SQLException {
		ps.setBigDecimal(i,new BigDecimal(parameter));
	}
	
	@Override
	public BigInteger getNullableResult(ResultSet rs, String columnName) throws SQLException {
		BigDecimal bigDecimal = rs.getBigDecimal(columnName);
		return bigDecimal==null?null:bigDecimal.toBigInteger();
	}
	
	@Override
	public BigInteger getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		BigDecimal bigDecimal = rs.getBigDecimal(columnIndex);
		return bigDecimal==null?null:bigDecimal.toBigInteger();
	}
	
}
